import request from '@/utils/request'
import { MessageBox } from 'element-ui'

// 查询智能柜列表列表
export function listSmartCabinet(query) {
  return request({
    url: '/smartCabinet/list',
    method: 'post',
    params: query
  })
}

// 查询智能柜列表详细
export function getSmartCabinet(id) {
  return request({
    url: '/smartCabinet/' + id,
    method: 'get'
  })
}

// 新增智能柜列表
export function addSmartCabinet(data) {
  return request({
    url: '/smartCabinet/add',
    method: 'post',
    data: data
  })
}

// 修改智能柜列表
export function updateSmartCabinet(data) {
  const res = request({
      url: '/smartCabinet/edit',
      method: 'post',
      data: JSON.stringify(data)
    })
  res.then(data => {
    if(data.msg == '500'){
      MessageBox({ message: data.data, type: 'error' })
    }
  })
  return res
}

// 删除智能柜列表
export function delSmartCabinet(ids) {
  return request({
    url: '/smartCabinet/remove',
    method: 'post',
    data: ids
  })
}

// 推送智能柜更新
export function updateCabinet(seriesNos) {
  const res = request({
    url: '/smartCabinet/updateCabinet',
    method: 'post',
    data: seriesNos
  })
  res.then(data => {
    if(data.msg == '500'){
      MessageBox({ message: data.data, type: 'error' })
    }
  })
  return res
}

// 获取存放柜子的列表  查询智能柜状态
export function getDrawerAll(seriesNo) {
  return request({
    url: '/cabinetDrawer/getDrawerAll/' + seriesNo,
    method: 'get'
  })
}


// 打开对应的智能柜  
export function openDrawer(drawerId) {
  return request({
    url: '/smartCabinet/openDrawer/' + drawerId,
    method: 'get'
  })
}




